<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<%@ taglib prefix="thx" uri="/thx-tags"%>

<style>
.form-horizontal .form-group {
	margin-right: 0px;
	margin-left: 0px;
}
</style>
<form id="app-field-form" name="ui-adminlte-form" class="form-horizontal"
	data-toggle="validator" role="form" method="post"
	action="${pageContext.request.contextPath}/workflow/field!save.action">
	<s:token></s:token>
	<input name="id" value="${entity.fieldId }" type="hidden" />
	<input name="appId" value="${appId}" type="hidden" />
	
	<div class="row">
		<div class="form-group col-sm-6">
			<label>字段名称 </label>
				<input type="text" name="entity.fieldText" value="${entity.fieldText}"
				remote="${pageContext.request.contextPath}/workflow/field!checkFieldText.action?appId=${appId}&id=${entity.fieldId }"
				 class="form-control required"
				placeholder="输入字段名称"/>
		</div>
		<div class="form-group col-sm-6">
			<label>字段代码</label>
				<input type="text" name="entity.fieldName" value="${entity.fieldName}"
				remote="${pageContext.request.contextPath}/workflow/field!checkFieldName.action?appId=${appId}&id=${entity.fieldId }"
				class="form-control required"
				placeholder="输入字段代码"/>
		</div>
	</div>
	<div class="row">
		<div class="form-group col-sm-6">
			<label>字段类型 </label>
			<select name="entity.fieldType" class="form-control" value="${entity.fieldType }">
				<c:forEach items="${fieldTypeList}" var="fieldType">
					<option value="${fieldType.key}" param="${fieldType.param}">${fieldType.name}</option>
				</c:forEach>
			</select>
		</div>
		<div class="form-group col-sm-6">
			<label>参数名称</label>
				<select name="entity.fieldOption" value="${entity.fieldOption}"	class="form-control">
				</select>
		</div>
	</div>
	<div class="row">
		<div class="form-group col-sm-6">
			<label>字段默认值 </label>
				<input type="text" name="entity.defaultValue" value="${entity.defaultValue}"
				 class="form-control"
				placeholder="输入字段默认值"/>
		</div>
		<div class="form-group col-sm-6">
			<label>字段长度</label>
				<input type="text" name="entity.fieldLength" value="${entity.fieldLength}"
				class="form-control"
				placeholder="输入字段长度"/>
		</div>
	</div>
	<div class="row">
		<div class="form-group col-sm-6">
			<label>字段顺序 </label>
				<input type="text" name="entity.seqenceNum" value="${entity.seqenceNum}"
				 class="form-control required"
				placeholder="输入字段顺序"/>
		</div>
		<div class="form-group col-sm-6">
			<label></label>
			<div class="form-control" style="border:none">
				<input type="checkbox" name="entity.isShow" value="Y" <c:if test="${entity.isShow=='Y'}">checked</c:if>
					placeholder="输入字段默认值"/>
				<label>是否显示 </label>
				&nbsp;&nbsp;&nbsp;
					<input type="checkbox" name="entity.isNecessary" value="Y" <c:if test="${entity.isNecessary=='Y'}">checked</c:if>
					placeholder="输入字段长度"/>
				<label>是否必填</label>
			</div>
		</div>
	</div>
</form>

<script>
	$(function() {
		appform.init();
		
		icheckPlugin.init($('#app-field-form input')); 

		$("#app-field-form select[name='entity.fieldType']").change(function(){
			$("#app-field-form [name='entity.fieldOption']").empty();
			if($(this).find("option:selected").attr("param")=="none"){
				$("#app-field-form [name='entity.fieldOption']").append("<option>暂无参数</option>");
				$("#app-field-form [name='entity.fieldOption']").attr("disabled","disabled");
			}else{
				$("#app-field-form [name='entity.fieldOption']").removeAttr("disabled");
				 $.ajax({
						url : ctxPath+"/workflow/field!findParam.action",
						data : "entity.fieldType="+$(this).find("option:selected").attr("param"),
						type : 'post',
						success : function(msg) {
							var data = eval(msg);
							for(var i=0;i<data.length;i++){
								$("#app-field-form [name='entity.fieldOption']").append("<option value="+data[i].id+">"+data[i].name+"</option>");
							}
						},
						error : function() {
						}
				 });
			}
		});
		$("#app-field-form select[name='entity.fieldType']").find("option[value='"+$("#app-field-form select[name='entity.fieldType']").attr("value")+"']").attr("selected","selected");
		$("#app-field-form select[name='entity.fieldType']").change();
	});
</script>